TO_BYTE block
Short summary
Name |
|
→POU type |
|
Category |
|
Conform to →IEC-standard |
currently restricted; see "Functionality" and more possible than defined in IEC-standard; see "Explicit conversion according to IEC-standard" |
Graphical interface |
|
Available since |
|
Functionality
The blocks serves for explicitly converting the value connected to input IN
into a value of data type BYTE
.
If the connected value is within the range of values overlapping for the data type of the input and for the result value BYTE
, the blocks returns this value.
Deviation from IEC-standard The IEC-standard defines that the conversion for the data types as defined by the IEC-standard is done as a binary transfer. However, this block deviates from the IEC-standard. The values of the data type |
Observe as well:
-
If a negative value of data type
REAL
orLREAL
is connected to the input, the blocks returns the value0
. If a negative value of a different data type is connected, the block returns a value according to the data type of the return value. -
If converting data types to the
TIME
data type and vice versa, the conversion is always based on seconds. -
If a value of data type
STRING
is connected to the input, the value is converted to a decimal value (base: 10, allowed digits:0
to9
) and then this decimal value is converted to a value according to the target data type . The following special cases might occur (see under "Example for usage within ST-editor"):-
If the value starts with the character
+
, with blanks or tabs (= so-called whitespace) and the value is within the range of values for the target data type, the value is converted to a positive decimal value (without these characters). In this case, the outputENO
is set to valueTRUE
.Details on this conversion: The character+
as prefix for the value is ignored, blanks and tabs (= so-called whitespace) are ignored as well. -
If the value starts with the character
–
and the value is within the range of values for the target data type, the value is converted analogously to a connected, negativeINT
value. In this case, the outputENO
is set to valueTRUE
as well.
Details on this conversion: The upper limit of the target data type is converted to the positive decimal value, this decimal value is increased by the value1
and then theSTRING
value (in fact the corresponding decimal value) is subtracted. The result is converted to a value appropriate to the target data type. -
If the value contains an invalid character, the block returns the value
0
. In this case, the outputENO
is set to valueFALSE
.Valid characters
invalid characters
digits (base: 10, numbers:
0
to9
)
Example for value with valid character:'7'
other characters such as letters
Example for value with invalid character:'12a3'
,'a123'
one character
+
or–
as a prefix of the value
Example for value with valid character:+2
or–3
repetitions of
+
or–
at the beginning of the value, the character+
or–
within the value
Example for value with invalid character:'++1'
,'1–3'
single underscore characters _ within the value
Example for value with valid character:1_2
or1_2_3
underscore character _ at the beginning or the end of the value, several characters _ behind one another
Example for value with invalid character:_12
,12_
or1__2
-
-
If the
STRING
value to be converted exceeds the upper limit of the target data type, the block returns the upper limit of the target data type. In this case, the outputENO
is set to valueFALSE
as well.
-
If a value of data type
CHAR
is connected to the input, the conversion is analogous to aSTRING
value. But different to theSTRING
conversion, theCHAR
conversion supports single digits digits0
to9
only. For all other characters (letters, the characters+
,-
and _), the block returns the value0
and the outputENO
is set to valueFALSE
.
Explicit conversion according to IEC-standard
The IEC-standard defines an explicit conversion of the following data types to BYTE
:
LINT, DINT, INT, SINT, ULINT, UDINT, UINT, USINT, LWORD, DWORD, WORD, BOOL, CHAR
The IEC-standard (Edition 3.0) defines a binary transfer for all data types of the input. But contrary to this, the appropriate value is converted according to the IEC-standard (Edition 2.0) for the following data types of the input.
CHAR
Details on the Neuron Power Engineer behavior of the block can be found in the section "Functionality".
Inputs, return value
|
Identifier |
Description |
|
---|---|---|---|
Inputs: |
|
|
value to be converted |
Return value: |
– |
|
|
Input EN
and output ENO
are available when →calling the block. See "Execution control: EN, ENO" for information on input EN
and output ENO
.
See:
-
"Blocks for safe logic" whether this block is supported for developing safety-relevant applications.
-
"Highlighting safe logic in the FBD-editor" for the effects when using the block as a block for safe logic.
Internal error diagnostic for block
The block checks the value connected to the input. The output ENO
of the block is set to value FALSE
(or an equivalent) in the following cases:
-
A
STRING
value contains an invalid character. (Moreover for this case, the block returns the value0
.) -
A
STRING
value exceeds the upper limit of the target data type. (Moreover for this case, the block returns the upper limit of the target data type.) -
The
CHAR
value is an invalid character. (Moreover for this case, the block returns the value0
.)
Example for usage within ST-editor
The calculated values are evaluated by using the Assert
block.
Example for DINT value |
---|
|
Example for STRING values |
---|
|
When creating your application within the ST-editor, enter a call of a block by typing the text as requested by the syntax or use Content Assist.